<template>
  <el-form ref="form" :model="form" label-width="150px" style="width: 350px" class="normal">
    <el-form-item label="医生姓名" >
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="手机号（登录凭证）">
      <el-input v-model="form.phonenumber" maxlength="11"></el-input>
    </el-form-item>
    <el-form-item label="科室">
      <el-select v-model="form.type" placeholder="请选择" @focus="selectTy()" style="float: left">
        <el-option
          v-for="item in tyinfo"
          :key="item.tyname"
          :label="item.tyname"
          :value="item.tyname">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="价格">
      <el-input v-model="form.price"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="form.sex"></el-input>
    </el-form-item>
    <!--<el-form-item label="价格">-->
      <!--<el-input v-model="form.price"></el-input>-->
    <!--</el-form-item>-->
    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
      <!--<el-button>取消</el-button>-->
    </el-form-item>
  </el-form>
</template>

<script>
    export default {
        name: "Addone1",
      data() {
        return {
          tyinfo: [],
          form: {
            name: '',
            phonenumber: '',
            hospital: '',
            type: '',
            sex:'',
            price:''
          }
        }
      },
      methods: {
        selectTy(){
          this.$ajax.get('http://47.75.110.31:8080/tyinfo/findAll')
            .then(response => {
              this.tyinfo = response.data;
              console.log(this.tyinfo[0].tyname)
            })
        },
        onSubmit() {
          console.log('submit!');
          if(this.form.name==''||this.form.type==''||this.form.phonenumber==''||this.form.sex==''){
            this.$message({
              message: '请填写完整的信息',
              type: 'warning'
            });
          }else {
            this.$ajax.post('http://47.75.110.31:8080/dcinfo/addOne?name='+this.form.name+'&sex='+this.form.sex+'&phonenumber='+this.form.phonenumber+'&hospital='+this.form.type+'&type='+this.form.type+'&price='+this.form.price,
              {

                headers: {
                  'Content-Type': 'application/json;charset=UTF-8'
                }
              }
            ).then(response => {
              console.log(response.data);
              if (response.data == "success") {
                this.$message({
                  message: '恭喜你添加成功',
                  type: 'success'
                });
                this.form.name='';
                this.form.type='';
                this.form.hospital='';
                this.form.phonenumber='';
                this.form.sex='';
                this.form.price= '';
              }
            })
          }
        }
      }
    }
</script>

<style scoped>
  .normal{
    font-size: 2rem;
  }
</style>
